<template>
  <div class="register-page">
    <div class="register-container">
      <!-- 标题 -->
      <h2>注册</h2>
      <p>创建一个新账号，开始您的旅行之旅。</p>

      <!-- 注册表单 -->
      <form @submit.prevent="handleRegister">
        <div class="form-group">
          <label for="username">用户名</label>
          <input
              type="text"
              id="username"
              v-model="registerForm.username"
              placeholder="请输入用户名"
              required
          />
        </div>
        <div class="form-group">
          <label for="email">邮箱地址</label>
          <input
              type="email"
              id="email"
              v-model="registerForm.email"
              placeholder="请输入邮箱"
              required
          />
        </div>
        <div class="form-group">
          <label for="password">密码</label>
          <input
              type="password"
              id="password"
              v-model="registerForm.password"
              placeholder="请输入密码"
              required
          />
        </div>
        <div class="form-group">
          <label for="confirmPassword">确认密码</label>
          <input
              type="password"
              id="confirmPassword"
              v-model="registerForm.confirmPassword"
              placeholder="请再次输入密码"
              required
          />
        </div>
        <button type="submit">注册</button>
      </form>

      <!-- 返回登录链接 -->
      <div class="back-to-login">
        <p>已有账号？<a href="/login">立即登录</a></p>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'RegisterPage',
  data() {
    return {
      // 注册表单数据
      registerForm: {
        username: '',
        email: '',
        password: '',
        confirmPassword: '',
      },
    };
  },
  methods: {
    // 处理注册
    handleRegister() {
      const { username, email, password, confirmPassword } = this.registerForm;

      // 简单表单验证
      if (!username || !email || !password || !confirmPassword) {
        alert('请填写所有字段！');
        return;
      }

      if (password !== confirmPassword) {
        alert('两次输入的密码不一致！');
        return;
      }

      // 模拟注册成功
      console.log('注册信息:', { username, email, password });
      alert('注册成功！');
      // 这里可以调用注册 API
    },
  },
};
</script>

<style scoped>
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@300;400;500;700&display=swap');
@import url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css');

.register-page {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #0e9aa7, #057885);
  font-family: 'Noto Sans SC', sans-serif;
  padding: 20px;
}

.register-container {
  background-color: white;
  border-radius: 15px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
  padding: 40px;
  width: 100%;
  max-width: 400px;
  text-align: center;
}

h2 {
  font-size: 1.8rem;
  margin-bottom: 10px;
  color: #333;
}

p {
  font-size: 0.9rem;
  color: #666;
  margin-bottom: 20px;
}

.form-group {
  margin-bottom: 20px;
  text-align: left;
}

label {
  display: block;
  font-size: 0.9rem;
  color: #555;
  margin-bottom: 5px;
}

input[type='text'],
input[type='email'],
input[type='password'] {
  width: 100%;
  padding: 12px;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.3s ease;
}

input[type='text']:focus,
input[type='email']:focus,
input[type='password']:focus {
  border-color: #0e9aa7;
}

button[type='submit'] {
  width: 100%;
  padding: 12px;
  background-color: #0e9aa7;
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 1rem;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

button[type='submit']:hover {
  background-color: #057885;
}

.back-to-login {
  margin-top: 20px;
  font-size: 0.9rem;
  color: #666;
}

.back-to-login a {
  color: #0e9aa7;
  text-decoration: none;
  transition: color 0.3s ease;
}

.back-to-login a:hover {
  color: #057885;
}

/* 响应式设计 */
@media (max-width: 480px) {
  .register-container {
    padding: 20px;
  }

  h2 {
    font-size: 1.5rem;
  }

  p {
    font-size: 0.8rem;
  }
}
</style>